{extend name="template/base" /}
{block name="content"}

<div style="margin-top: 50px">
    <div class="cl pd-5 bg-1 bk-gray">
         <span class="l pt-5 pr-5">
             <span style="margin: 5px">派车单：<strong>{$group.id}</strong>&nbsp;&nbsp;&nbsp;&nbsp;标题：<strong>{$group.title}</strong></span>
             <input type="button" id="group_id" value="{$group.id}" style="display: none" />
             <input type="button" id="dispatch_group_status" value="{$group.dispatch_group_status}" style="display: none" />
         </span>
         <span class="l pt-5 pr-5" style="margin-left: 10px">
             {if $unf != 1}
              <!--<a style="text-decoration:none" class="label label-warning radius" onclick="layer_open('添加订单','/admin/dispatch_traveler_group/add_single_order_to_dispatch/id/{$group.id}')">添加订单</a>-->
              <a style="text-decoration:none" class="label label-warning radius" onclick="allScatter(this)">全部打散</a>
             {/if}
         </span>
         <span class="r pt-5 pr-5">
                共有订单数据 ：<strong>{$count ?? '0'}</strong> 条
         </span>
        <table class="table table-border table-bordered table-hover table-bg mt-20">
            <tbody>
            <tr class="text-c">
                <th colspan="2">出车时间</th>
                {if $group['is_pickup'] == 1}
                <th colspan="2" style="font-weight:normal">{$pick_up_time}</th>
                {else/}
                <th colspan="2" style="font-weight:normal">{:date('Y-m-d',$group.go_date)}</th>
                {/if}

                <th colspan="2">线路名称</th>
                <th colspan="2" style="font-weight:normal">{$group.route_title}</th>
            </tr>
            {if $group.is_pickup == '1'}
            <tr class="text-c">
                <th colspan="2">接机地点</th>
                <th colspan="2" style="font-weight:normal">{$location}</th>
                <th colspan="2">接机时间</th>
                <th colspan="2" style="font-weight:normal">{$pick_up_time}</th>
            </tr>
            {/if}
            <tr class="text-c">
                <th colspan="2">出车师傅</th>
                <th colspan="2" style="font-weight:normal">{$group.driver_user_name}</th>
                <th colspan="2">司机手机</th>
                <th colspan="2" style="font-weight:normal">{$group.driver_user_mobile}</th>
            </tr>
            <tr class="text-c">
                <th colspan="2">车辆信息</th>
                <th colspan="6" style="font-weight:normal">{$group.car_info}</th>
            </tr>
            <tr class="text-c">
                <th colspan="2">线路</th>
                <th colspan="6" style="font-weight:normal">{$group.route_pass}</th>
            </tr>
            <tr class="text-c">
                <th colspan="2">备注</th>
                <th colspan="6" style="font-weight:normal;max-width: 400px">{$group.remark}</th>
            </tr>
            <tr class="text-c" style="display: none">
                <th colspan="2">备注</th>
                <th colspan="6" style="font-weight:normal;max-width: 400px">
                    <ul class="linenums" id="text_remark{$k}">
                        {volist name="$group.dtg_remark" id="li" key="key"}
                        <li>{$key}、{$li.content}</li>
                        {/volist}
                    </ul>
                    <textarea id="input_remark{$k}"
                              style="display: none; width: 400px; height: 200px; margin:0 auto 5px"></textarea>
                    <a id="edit_remark{$k}" href="javascript:;" onclick="edit_remark('{$k}')" style="text-decoration:none; margin-right: 5px"
                       class="label label-success radius" title="添加">添加</a>
                    <a id="more_remark{$k}" href="javascript:;" onclick="layer_open('备注信息','/admin/dispatch_traveler_group/dispatch_remark/dtg_id/{$group.id}')" style="text-decoration:none; margin-right: 5px"
                       class="label label-success radius" title="更多">更多</a>
                    <a id="save_remark{$k}" href="javascript:;" onclick="save_remark('{$k}','{$group.id}')"
                       style="text-decoration:none; display: none; margin-right: 5px" class="label label-success radius"
                       title="保存">保存</a>
                    <a id="cancel_remark{$k}" href="javascript:;" onclick="cancel_remark('{$k}')"
                       style="text-decoration:none; display: none" class="label label-success radius" title="取消">取消</a>
                </th>
            </tr>

            </tbody>
        </table>
    </div>
</div>

<div style="padding: 10px">
    {volist id='order_travelers' name='order_traveler'}
    <table class="table table-border table-bordered table-hover table-bg mt-20">
        {volist id='travelers' name='order_travelers'}
        {if $i==1}
            <thead>
                <tr class="text-c">
                    <th colspan="2">订单号:{$travelers.oid}</th>
                    <th colspan="12" style="font-weight:normal">
                        {if $unf != 1}
                            <a style="text-decoration:none" data-val="{$travelers.oid}" class="r label label-warning radius" onclick="scatter(this)">打散</a>
                        {/if}
                    </th>
                </tr>
            </thead>
        {/if}
        <tbody>
                <tr class="text-c">
                    {if $i==1}
                        <th colspan="1">旅客信息</th>
                    {else /}
                        <th colspan="1"></th>
                    {/if}
                    <th colspan="1">旅客姓名</th>
                    <th colspan="2" style="font-weight:normal">{$travelers.name}</th>
                    <th colspan="1">性别</th>
                    <th colspan="2" style="font-weight:normal">{$travelers.sex}</th>
                    <th colspan="1">年龄</th>
                    <th colspan="2" style="font-weight:normal">{$travelers.age}</th>
                    <th colspan="1">旅客手机</th>
                    <th colspan="2" style="font-weight:normal">{$travelers.phone}</th>
                </tr>
                <!--<tr class="text-c">-->
                    <!--<th colspan="1"></th>-->
                    <!--<th colspan="1">订单旅客备注</th>-->
                    <!--<th colspan="5" style="font-weight:normal">{$travelers.phone}</th>-->
                <!--</tr>-->
        </tbody>
        {/volist}
        <tr class="text-c">
            <th colspan="1">订单备注</th>
            <th colspan="12" style="font-weight:normal">
                <ul>
                    {volist name="$travelers.order_remark" id="li" key="key"}
                    <li>{$key}、{$li.content}</li>
                    {/volist}
                </ul>
                <a id="relevance_more_remark{$k}" href="javascript:;" onclick="layer_open('备注信息','/admin/order/remark/order_id/{$travelers.oid}')" style="text-decoration:none;"
                   class="label label-success radius" title="更多">更多</a>
            </th>
        </tr>
    </table>
    {/volist}

</div>
<div class="page-bootstrap">{$page ?? ''}</div>
{/block}
{block name="script"}
<script>
    // 显示修改备注
    function edit_remark(e) {
        // var text = $('#text_remark' + e).text();
        $('#text_remark' + e).css('display', 'none');
        $('#edit_remark' + e).css('display', 'none');
        // $('#input_remark' + e).val(text);
        $('#input_remark' + e).css('display', 'block');
        $('#save_remark' + e).css('display', 'inline-block');
        $('#cancel_remark' + e).css('display', 'inline-block');
    }
    // 添加备注
    function save_remark(e, dtg_id) {
        var remark = $('#input_remark' + e).val();
        $.ajax({
            type: 'POST',
            url: "/admin/dispatch_traveler_group/add_dispatch_remark?dtg_id=" + dtg_id + "&remark=" + remark,
            data: null,
            success: function (re) {
                if (re.msg) {
                    layer.msg(re.msg, {
                        time: 1000, //1s后自动关闭
                    }, function () {
                        //关闭后刷新
                        location.reload();
                    });
                }
            }
        });
    }
    // 取消备注
    function cancel_remark(e) {
        $('#text_remark' + e).css('display', 'inline');
        $('#edit_remark' + e).css('display', 'inline');
        $('#input_remark' + e).css('display', 'none');
        $('#save_remark' + e).css('display', 'none');
        $('#cancel_remark' + e).css('display', 'none');
    }
    function unopened(e){
        console.log('ee',$(e))
        layer.msg("该功能暂未开放", {
            time: 1500, //1.5s后自动关闭
        });
        return ;

    }
    function addOrder(id) {
        $.ajax({
            type: 'post',
            url: '/admin/dispatch_traveler_group/add_single_order_to_dispatch',
            data:{
                id: id,
            },
            success: function (data) {
//                            操作成功
                if (data.status){
                    console.log('1',data);
                    console.log('data',data.data);
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 1500 //1.5秒关闭
                    }, function(){
                        window.parent.location.reload(); //刷新父页面
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index)
                    });
                }else{
//                                操作失败
                    console.log('2',data);
                    layer.msg(data.msg, {
                        icon: 5,
                        time: 1500 //1.5秒关闭
                    }, function(){
                        location.reload();
                    });
                }
            },
            error:function(data){
//                            发生异常
                console.log('data', data);
                layer.msg('发生错误', {
                    icon: 5,
                    time: 1500 //1.5秒关闭
                })
            }
        })
    }
    //单个打散
    function scatter(e) {
        var dispatch_group_status =  $('#dispatch_group_status').val();
        var dispatch_status = '';
        switch (dispatch_group_status){
            case 'undistributed':
                dispatch_status = '未分配';
                break;
            case 'sendorders':
                dispatch_status = '派单中';
                break;
            case 'receiving':
                dispatch_status = '已接单';
                break;
            case 'proceed':
                dispatch_status = '进行中';
                break;
            default:
                layer.msg('此派车单当前状态不可进行打散操作！', {
                    icon: 5,
                    time: 1500 //1.5秒关闭
                }, function(){
//                    location.reload();
                });
                return
        }

        var order_id = $(e).attr('data-val');
        var id = $('#group_id').val();
        $.ajax({
            type: 'post',
            url: '/admin/dispatch_traveler_group/scatter',
            data:{
                id: id,
                order_id: order_id,
            },
            success: function (data) {
//                            操作成功
                if (data.status){
                    console.log('1',data);
                    console.log('data',data.data);
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 1500 //1.5秒关闭
                    }, function(){
                        window.parent.location.reload(); //刷新父页面
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index)
                    });
                }else{
//                                操作失败
                    console.log('2',data);
                    layer.msg(data.msg, {
                        icon: 5,
                        time: 1500 //1.5秒关闭
                    }, function(){
                        location.reload();
                    });
                }
            },
            error:function(data){
//                            发生异常
                console.log('data', data);
                layer.msg('发生错误', {
                    icon: 5,
                    time: 1500 //1.5秒关闭
                })
            }
        });
        console.log('id',id)
    }
//    全部打散
    function allScatter(id) {
        var dispatch_group_status =  $('#dispatch_group_status').val();
        var dispatch_status = '';
        switch (dispatch_group_status){
            case 'undistributed':
                dispatch_status = '未分配';
                break;
            case 'sendorders':
                dispatch_status = '派单中';
                break;
            case 'receiving':
                dispatch_status = '已接单';
                break;
            default:
                layer.msg('此派车单当前状态不可进行全部打散操作！', {
                    icon: 5,
                    time: 1500 //1.5秒关闭
                }, function(){
//                    location.reload();
                });
                return
        }
        //示范一个公告层
        layer.open({
            type: 1
            ,title: false //不显示标题栏
            ,closeBtn: false
            ,area: '300px;'
            ,shade: 0.8
            ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
            ,btn: ['确认继续', '取消操作']
            ,btnAlign: 'c'
            ,moveType: 1 //拖拽模式，0或者1
            ,content: '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">您正在进行‘全部打散’ 操作！<br><br>该派车单处于‘'+ dispatch_status +'’状态！<br>该操作将会产生的影响：<br>1.将会删除此派车单信息以及相关的房调信息<br>2.此派车单的所有订单回滚为未分配状态。<br>3.此派车单下所有订单的订单状态将会更改为异常状态<br>是否继续进行？<br></div>'
            ,success: function(layero){
                var id = $('#group_id').val();
                console.log('id',id);
                //确认按钮
                $(".layui-layer-btn0").click(function(){
                    console.log('123');
                    $.ajax({
                        type: 'post',
                        url: '/admin/dispatch_traveler_group/all_scatter',
                        data:{
                            id: id
                        },
                        success: function (data) {
//                            操作成功
                            if (data.status){
                                console.log('1',data);
                                console.log('data',data.data);
                                layer.msg(data.msg, {
                                    icon: 1,
                                    time: 1500 //1.5秒关闭
                                }, function(){
                                    window.parent.location.reload(); //刷新父页面
                                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                    parent.layer.close(index)
                                });
                            }else{
//                                操作失败
                                console.log('2',data);
                                layer.msg(data.msg, {
                                    icon: 5,
                                    time: 1500 //1.5秒关闭
                                }, function(){
                                    location.reload();
                                });
                            }
                        },
                        error:function(data){
//                            发生异常
                            console.log('data', data);
                            layer.msg('发生错误', {
                                icon: 5,
                                time: 1500 //1.5秒关闭
                            })
                        }
                    })
                });
                //取消按钮
                $(".layui-layer-btn1").click(function(){
                    console.log('已取消操作');
                });
            }
        });

        return ;

    }
</script>
{/block}